package com.demo.controller;


import java.util.Date;
import java.util.List;

import com.demo.annotation.GlobalInterceptor;
import com.demo.annotation.VerifyParam;
import com.demo.entity.constants.Constants;
import com.demo.entity.dto.SessionWebUserDto;
import com.demo.entity.po.GroupMember;

import com.demo.entity.query.GroupMemberQuery;

import com.demo.entity.vo.PaginationResultVO;

import com.demo.entity.vo.ResponseVO;

import org.aspectj.apache.bcel.classfile.Constant;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.demo.service.GroupMemberService;

/**
 * @Description:小组成员表Controller
 * @Date:2025-03-01
 * @author：author
*/
@RestController("groupMemberController")
@RequestMapping("/group")
public class GroupMemberController extends ABaseController {

	@Resource
	private GroupMemberService groupMemberService;


	/**
	 * 查询小组成员
	 */
	@RequestMapping("/loadGroupMember")
	@GlobalInterceptor(checkParams = true)
	public ResponseVO loadDataList(HttpSession session,
								   GroupMemberQuery query) {
		List<GroupMember> groupMembers = groupMemberService.loadGroupMember(query);
		return getSuccessResponseVO(groupMembers);
	}




	/**
	 * 批量添小组成员
	 */
	@RequestMapping("/add2Group")
	@GlobalInterceptor
	public ResponseVO add2Group(@VerifyParam(required = true) Long groupId,
									   @VerifyParam(required = true) Long userId) {
		GroupMember groupMember = new GroupMember();
		groupMember.setGroupId(groupId);
		groupMember.setUserId(userId);
		groupMember.setJoinTime(new Date());
		groupMember.setRole(Constants.ZERO);
		groupMemberService.add(groupMember);
		return getSuccessResponseVO(null);
	}


	/**
	 * 退出小组
	 * @param groupId 小组id
	 * @param userId 用户Id
	 * @return
	 */
	@RequestMapping("/removeMember")
	@GlobalInterceptor
	public ResponseVO removeMember(@VerifyParam(required = true) Long groupId,
								   @VerifyParam(required = true) Long userId) {
		this.groupMemberService.delInfo(groupId,userId);
		return getSuccessResponseVO(null);
	}

}